package com.dycx.api.controller.manage.user;

import com.dycx.common.RestResponse;
import com.dycx.common.annotation.WriterLog;
import com.dycx.common.enums.BizTypeEnum;
import com.dycx.user.dto.SellerDTO;
import com.dycx.user.enums.SellerStatusEnum;
import com.dycx.user.service.SellerService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


@RestController
@RequestMapping(value = "/manage/user/seller")
public class SellerController {

    @Resource
    private SellerService sellerService;

    /**
     * 刪除
     **/
    @WriterLog(bizType = BizTypeEnum.USER_SELLER, bizValue = "{#id}")
    @GetMapping("/delete")
    public RestResponse<?> delete(int id) {
        return sellerService.delete(id) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 更新
     **/
    @WriterLog(bizType = BizTypeEnum.USER_SELLER, bizValue = "{#sellerDto.id}")
    @PostMapping("/checkSeller")
    public RestResponse<?> checkSeller(@RequestBody SellerDTO sellerDto) {
        return sellerService.checkSeller(sellerDto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 查询 根据主键 id 查询
     **/

    @GetMapping("/getInfoById")
    public RestResponse<?> getInfoById(int id) {
        return RestResponse.success(sellerService.getInfoById(id));
    }


    /**
     * 查询 分页查询
     **/

    @PostMapping("/getPage")
    public RestResponse<?> getPage(@RequestBody SellerDTO sellerDto) {
        return RestResponse.success(sellerService.getPage(sellerDto));
    }

    /**
     * 新增商家
     **/
    @WriterLog(bizType = BizTypeEnum.USER_SELLER, bizValue = "{#sellerDto.id}")
    @PostMapping("/addSeller")
    public RestResponse<?> addSeller(@RequestBody @Valid SellerDTO sellerDto) {
        return sellerService.addSeller(sellerDto) ? RestResponse.success() : RestResponse.fail();
    }


    /**
     * 修改
     * @param sellerDto
     * @return
     */
    @WriterLog(bizType = BizTypeEnum.USER_SELLER, bizValue = "{#sellerDto.id}")
    @PostMapping("/edit")
    public RestResponse<Boolean> edit(@RequestBody @Valid SellerDTO sellerDto) {
        return sellerService.edit(sellerDto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 查看商家身份证号
     *
     * @param sellerId
     * @return
     */
    @WriterLog(bizType = BizTypeEnum.USER_SELLER, bizValue = "{#sellerId}")
    @GetMapping("/lookSellerIdCard")
    public RestResponse<?> lookSellerIdCard(int sellerId) {
        return RestResponse.success(sellerService.lookSellerIdCard(sellerId));
    }

}
